package com.crm.service.impl.csd.customerManager;

import com.crm.dao.mapper.csd.customerManager.CustomerInfoMapper;
import com.crm.dao.mapper.customMapper.csd.CustomerListMapper;
import com.crm.dao.mapper.customerManager.CustomerMapper;
import com.crm.model.entity.csd.customerManager.CustomerInfo;
import com.crm.model.entity.customerManager.Customer;
import com.crm.model.qo.csd.customerManager.CustomerInfoQO;
import com.crm.model.qo.csd.customerManager.CustomerQO;
import com.crm.model.vo.csd.customerManager.CustomerDetailVO;
import com.crm.model.vo.csd.customerManager.CustomerInfoVO;
import com.crm.model.vo.csd.customerManager.CustomerVO;
import com.crm.model.vo.csd.customerManager.ImportCustomerInfoVO;
import com.crm.service.csd.customerManager.CustomerDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yincuimei
 * @Date 2021/7/23 11:12
 * (客服部)-客户管理
 */
@Service("csdCustomerDbServiceImpl")
public class CustomerDbServiceImpl implements CustomerDbService {

    @Autowired
    private CustomerListMapper customerListMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private CustomerInfoMapper customerInfoMapper ;


    /**
     * 客户列表
     * @param customerQO --查询条件
     * @param orderStr   --排序
     * @author yincuimei
     * @return
     */
    @Override
    public List<CustomerVO> selectCustomerVOList(CustomerQO customerQO, String orderStr) {
        return customerListMapper.selectCustomerList(customerQO,orderStr);
    }

    /**
     * 会员客户列表
     * @param customerQO --查询条件
     * @param orderStr   --排序
     * @author wangpeng
     * @return
     */
    @Override
    public List<CustomerVO> selectCustomerMemberList(CustomerQO customerQO, String orderStr) {
        return customerListMapper.selectCustomerMemberList(customerQO,orderStr);
    }


    /**
     * 非会员客户列表
     * @param customerQO --查询条件
     * @param orderStr   --排序
     * @author wangpeng
     * @return
     */
    @Override
    public List<CustomerVO> selectCustomerNonMemberList(CustomerQO customerQO, String orderStr) {
        return customerListMapper.selectCustomerNonMemberList(customerQO,orderStr);
    }

    /**
     * 客户详情(企业客户)
     * @param customerId --客户ID
     * @author yincuimei
     * @return
     */
    @Override
    public CustomerDetailVO selectCustomerDetailVO(String customerId) {
        return customerListMapper.selectCustomerDetailVO(customerId);
    }

    /**
     * 客户编辑(企业客户)
     * @param customer
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean updateCustomerByCustomerId(Customer customer) {
        return customerMapper.updateByPrimaryKeySelective(customer) > 0;
    }

    /**
     * 收回客户-修改客户信息
     * @param customer
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean updateRetrieveCustomer(Customer customer){
        return customerListMapper.updateRetrieveCustomer(customer) > 0;
    }
    /**
     * 客户列表--操作解锁
     * @param customerId --客户ID
     * @author wangpeng
     * @return
     */
    @Override
    public Boolean updateCustomerMembershipLevelUnlock(String customerId) {
        return customerListMapper.updateCustomerMembershipLevelUnlock(customerId);
    }
    /**
     * 客户列表--操作锁定
     * @param customerId --客户ID
     * @author wangpeng
     * @return
     */
    @Override
    public Boolean updateCustomerMembershipLevelLocking(String customerId) {
        return customerListMapper.updateCustomerMembershipLevelLocking(customerId);
    }

    /**
     * selectCustomerInfoList
     * @Author wangpeng
     * @Date 2021/9/27
     * @param customerQO
     * @param order
     * @return
     */
    @Override
    public List<CustomerInfoVO> selectCustomerInfoList(CustomerInfoQO customerQO, String order) {
        return customerListMapper.selectCustomerInfoList(customerQO,order);
    }

    /**
     * addCustomerInfo
     * @Author wangpeng
     * @Date 2021/10/12
     * @param list	
     * @return
     */
    @Override
    public void addCustomerInfo(List<CustomerInfo> list) {
        customerListMapper.addCustomerInfo(list);
    }

    /**
     * exportExcel
     * @Author wangpeng
     * @Date 2021/10/12
     * @param 	
     * @return
     */
    @Override
    public List<ImportCustomerInfoVO> exportExcel() {
        return customerListMapper.exportExcel();
    }

    @Override
    public List<CustomerInfoVO> selectProviceList() {
        return  customerListMapper.selectProviceList();
    }

    @Override
    public List<CustomerInfoVO> selectCityByProvice(String provice) {
        return customerListMapper.selectCityByProvice(provice);
    }

    @Override
    public List<CustomerInfoVO> selectDistrictByProviceCity(String provice, String city) {
        return customerListMapper.selectDistrictByProviceCity(provice,city);
    }

    @Override
    public List<CustomerInfoVO> selectIndustryTypeList() {
        return customerListMapper.selectIndustryTypeList();
    }

    @Override
    public CustomerInfo getCustomerInfoDetailByCustomerInfoId(String customerInfoId) {
        //使用example返回的text类型的字段为空
        //CustomerInfoExample customerInfoExample = new CustomerInfoExample();
        //CustomerInfoExample.Criteria criteria = customerInfoExample.createCriteria();
        //criteria.andCustomerInfoIdEqualTo(customerInfoId);
        //criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        //return customerInfoMapper.selectByExample(customerInfoExample);
        return customerListMapper.getCustomerInfoDetailByCustomerInfoId(customerInfoId);
    }

    /**
     * 【客服部】客户信息库列表-详细-调整
     * @param customerInfo
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean updateCompanyAndAccountById(CustomerInfo customerInfo) {
        return customerInfoMapper.updateByPrimaryKeySelective(customerInfo) > 0;
    }
}
